package com.epfresh.supplier.entity;

import android.util.Log;

import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.List;

public class CategoryAll {
    private List<Category> item;
    private String name;
    private String id;
    private String icon;

    private boolean select;

    public List<Category> getItem() {
        return item;
    }

    public void setItem(List<Category> item) {
        this.item = item;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public boolean isSelect() {
        return select;
    }

    public void setSelect(boolean select) {
        this.select = select;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }


    public List<CategoryNames> getNames() {

        List<CategoryNames> names = new ArrayList<>();
        if (item != null && item.size() > 0) {

            for (int i = 0; i < item.size(); i++) {
                Category pc = item.get(i);

                List<CategoryNames> pNames = pc.getNames();
                if (pNames != null && pNames.size() > 0) {
                    CategoryNames pn = new CategoryNames();
                    pn.setName(pc.getName());
                    pn.setId(pc.getId());
                    pn.setTitle(true);
                    names.add(pn);


                    int n = pNames.size();

                    for (int j = 0; j < n; j++) {

                        CategoryNames categoryNames = pNames.get(j);
                        categoryNames.setParentId(pc.getId());
                        categoryNames.setParentType(pc.getType());
                        names.add(categoryNames);


                    }

                    n = n % 3;
                    if (n != 0) {
                        n = 3 - n;
                    }
                    for (int j = 0; j < n; j++) {
                        CategoryNames categoryNames = new CategoryNames();
                        categoryNames.setEmpty(true);

                        names.add(categoryNames);
                    }

                }


            }
        }


        return names;
    }

    @Override
    public String toString() {
        return "CategoryAll{" +
                "categories=" + item +
                ", name='" + name + '\'' +
                ", id='" + id + '\'' +
                ", select=" + select +
                '}';
    }
}
